<?php

class User {
    
    protected $CI;
    
    public $id;
    
    public function __construct() {
        $this->CI =& get_instance();
        if ($this->CI->session->userdata('uid')) {
            $this->_init();
        }
    }
    
    protected function _init() {
        $uid = $this->CI->session->userdata('uid');
        $this->CI->load->model('user_model');
        $user_data = $this->CI->user_model->get_user($uid);
        // 数据库中不存在此uid
        if (! $user_data) {
            return false;
        }
        foreach ($user_data as $u_key => $u_val) {
            $this->$u_key = $u_val;
        }
        $this->id = $this->user_id ? $this->user_id : null;
    }
    
}